/*
 * Copyright 2008 Neil Bacon
 * Distributed under the terms of the Mozilla Public License version 1.1
 * or the GNU General Public License version 3.
 */

package nb.ref.impl;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;

import nb.ref.ValueReference;
import nb.ref.ValueReferenceFactory;

public class ValueSoftReferenceFactory<K, V> implements ValueReferenceFactory<K, V> {

    public ValueReference<K, V> get(K key, V value, ReferenceQueue<? super V> queue) {
        return new ValueSoftReference<K, V>(key, value, queue);
    }


    // nested classes ...

    private static class ValueSoftReference<K, V> extends SoftReference<V>  implements ValueReference<K, V> {

        private final K key;

        public ValueSoftReference(K key, V value, ReferenceQueue<? super V> queue) {
            super(value, queue);
            this.key = key;
        }

        public K getKey() {
            return key;
        }

    }

}
